package com.example.day08.controller;

import com.example.day08.pojo.Emp;
import com.example.day08.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/emp")
@CrossOrigin(allowedHeaders = "*")
@Slf4j
public class EmpController {
    @Autowired
    private EmpService empService;

    @RequestMapping("/findALL")
    public List<Emp> findAll(Model model){
        List<Emp> list = empService.findAll();
        model.addAttribute("list",list);
        return list;
    }

    @RequestMapping("/add")
    public void add(@RequestBody Emp emp){
        empService.add(emp);
    }

    @RequestMapping("/ding")
    @Scheduled(cron = "0 0 8 * * ?")
    public void ding(){
        Integer a=  empService.ding();
        log.info("aa:{}",a);
        empService.save(a);
    }
}
